<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .butstart {
            background-color: gray;
            width: 60px;
            height: 30px;
        }

        .box {
            background-color: aqua;
            width: 300px;
            height: 300px;
        }

        .butstop {
            background-color: gray;
            width: 60px;
            height: 30px;
        }
    </style>
</head>

<body>
    <h1>随机问答</h1>
    <div class="box">猜猜我是谁</div>
    <button class="butstart">开始</button>
    <button class="butstop">结束</button>
    <script>
        const names = ['周杰伦', '刘德华', '周星驰', '墙壁漏电', '张学友'];
        const box = document.querySelector('.box')
        const btnstart = document.querySelector('.butstart');
        const btnstop = document.querySelector('.butstop');
        let time = null;
        btnstart.addEventListener('click', function () {
            if (time !== null)
                return;
        })
        time = setInterval(function () {
            const ran = Math.floor(Math.random() * name.length);
            box.textContent = names[ran];
        }, 80)
        btnstop.addEventListener('click', function () {
            clearInterval(time);
            time = null
        })

    </script>
</body>

</html>